<?php

session_start();
    include '../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $tc = 1;
    
    if($tc == 1){
        
        $areas = $_REQUEST['area'];
        $estado = $_REQUEST['estado'];
        
        if($estado == '8'){
            $estados = '' ;
        }else{
            $estados = "and dnsolicitud.dnsestado = ".$estado;
        }
        
        
        $fec = $_REQUEST['fecha1'];
        $fecha1 = date('Y-m-d 00:00.000',strtotime($fec));
        $fec2 = $_REQUEST['fecha2'];
        $fecha2 = date('Y-m-d 23:59:00.000',strtotime($fec2));
        
        $select = "select  dnsoid,case when dnconducta.conpertinen is null then '' else dnconducta.conpertinen end as conpertinen,
                           case when dnconducta.conpriorid is null then '' else dnconducta.conpriorid end as conpriorid,
                           case when dnconducta.confecump is null then '' else dnconducta.confecump end as confecump,
                           case when dnconducta.condias is null then '' else dnconducta.condias end as condias,dnsolicitud.dnsoid,
                           LTRIM(RTRIM(usu_nombres)) +' '+ LTRIM(RTRIM(usu_apellidos)) as nombres,dnsolicitud.dnsestado,
                           GENDEPEND.GDPNOMBRE,dnmecanisdet.mecnombre,cast(dnsolicitud.dnsdescri as text)as dnsdescri,cast(dnsolicitud.dnsjustifi as text)as dnsjustifi,dnfecha
                    from dnsolicitud left outer  join usuario on dnsolicitud.usu_oid = usuario.usu_oid
                                     left outer join DGempres10..GENDEPEND on dnsolicitud.dnservicio = GENDEPEND.OID
                                     left outer join dnmecanisdet on dnsolicitud.mecoid = dnmecanisdet.mecoid
                                     left outer join dnconducta on dnsolicitud.dnsoid = dnconducta.sol_oid
                   where tipoid = ".$areas." and dnsolicitud.dnfecha between '".$fecha1."' and '".$fecha2."' ".$estados." and dnsolicitud.usu_oid not in(537)";
        $res = $con->query($select);
        
        while ($res2 = mssql_fetch_array($res)){
            
            $lista[] = $res2;
            
        }
        
        print_r(json_encode($lista));
        
    }
    
    $con->cerrarConexion();


?>
